/*
 * @Author: Dorange.Wang
 * @Date: 2021-04-01 11:00:35
 * @LastEditors: wangming
 * @LastEditTime: 2022-01-26 11:04:40
 * @Description: file content
 */
const devConfig = {
  httpProtocol: 'http://',
  wsProtocol: 'ws://',
  // hostname: '172.28.101.231',
  // hostname: '172.28.101.152',
  // port: '8089',
  hostname: 'hanma-paas-dev.hc-iiot.com',
  port: '',
  prefix: '',
  wsPath: '',
  domainSuffix: 'lesscode'
}

const prodConfig = {
  httpProtocol: window.location.protocol + '//',
  wsProtocol: window.location.protocol === 'https:' ? 'wss://' : 'ws://',
  hostname: window.location.hostname,
  port: window.location.port,
  prefix: '',
  wsPath: '',
  domainSuffix: (window.location.host.match(/-([a-z]+)[.-]/) || [''])[1]
}

const apiConfig = process.env.NODE_ENV === 'production' ? prodConfig : devConfig
const { httpProtocol, hostname, port, prefix } = apiConfig

export default apiConfig
export const baseURL = `${httpProtocol}${hostname}${port ? ':' + port : ''}${prefix}`

export const getBasePath = function (path, serve = '/paas') {
  if (process.env.VUE_APP_ROOT_URL === './') {
    serve = ''
  }
  if (path.substr(0, 1) !== '/') {
    path = '/' + path
  }
  return `${baseURL}${serve}${path}`
}
